package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatis.service.impl.CrudServiceImpl;
import com.example.dao.CartDao;
import com.example.dto.CartDTO;
import com.example.entity.CartEntity;
import com.example.service.CartService;
import com.example.utils.ConvertUtils;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 购物车表
 *
 * @author yyyyjinying 1020066395@qq.com
 * @since 1.0-SNAPSHOT 2025-05-22
 */
@Service
public class CartServiceImpl extends CrudServiceImpl<CartDao, CartEntity, CartDTO> implements CartService {

    @Override
    public QueryWrapper<CartEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<CartEntity> wrapper = new QueryWrapper<>();

        String type = (String)params.get("type");
        wrapper.eq(StringUtils.isNotBlank(type), "type", type);

        return wrapper;
    }

    @Override
    public void save(CartDTO dto) {
        CartEntity entity = ConvertUtils.sourceToTarget(dto, CartEntity.class);
        entity.setId(snowflake.nextId()); // 主键id可能有错误
        baseDao.insert(entity);
    }


}